﻿using SetSailDal;
using SetSailModel;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SetSailView
{
    /// <summary>
    /// 信息变更
    /// </summary>
    public partial class Frm_XXBG : UserControl
    {
        public Frm_XXBG()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 修改 密码
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ucBtnExt2_BtnClick(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(ucTextBoxEx2.InputText.Trim()))
            {
                MessShow.ShowHint("请输入旧密码");
                return;
            }
            if (string.IsNullOrWhiteSpace(ucTextBoxEx1.InputText.Trim()))
            {
                MessShow.ShowHint("请输入新密码");
                return;
            }

            if (ucTextBoxEx1.InputText.Trim().Length < 8)
            {
                MessShow.ShowHint("密码不能低于八位");
                return;
            }

            if (string.IsNullOrWhiteSpace(ucTextBoxEx3.InputText.Trim()))
            {
                MessShow.ShowHint("请输入确认密码");
                return;
            }
            if (ucTextBoxEx1.InputText.Trim() != ucTextBoxEx3.InputText.Trim())
            {
                MessShow.ShowHint("两次密码输入不一致");
                return;
            }
            if (CookieData.getInstance().YHXX.DLMM != SetSailCommon.CommonHelper.MD5Encrypt(ucTextBoxEx2.InputText.Trim()))
            {
                MessShow.ShowHint("原密码错误");
                return;
            }
            var res = XXBGDal.EditPWD(CookieData.getInstance().YHXX.ID, SetSailCommon.CommonHelper.MD5Encrypt(ucTextBoxEx3.InputText.Trim()));
            MessShow.ShowHint(res.Message);

            SetSailReadFileTools.Properties.Settings.Default.Password = "";
            SetSailReadFileTools.Properties.Settings.Default.IsSavePwd = false;
            this.ParentForm.Close();
            Frm_Login login = new Frm_Login();
            login.Show();

        }

        private void ucBtnExt1_BtnClick(object sender, EventArgs e)
        {
            CookieData.getInstance().YHXX.QQ = txt_QQ.InputText;
            CookieData.getInstance().YHXX.YY = txt_YY.InputText;
            CookieData.getInstance().YHXX.ZBFJH = txt_ZBFJH.InputText;
            CookieData.getInstance().YHXX.DDLX = cob_DDLX.SelectedValue;
            CookieData.getInstance().YHXX.ZBFS = cob_ZBFS.SelectedValue;
            var user = CookieData.getInstance().YHXX;

            var res = XXBGDal.EditYHXX(user);
            MessShow.ShowHint(res.Message);
        }

        private void Frm_XXBG_Load(object sender, EventArgs e)
        {
            this.init();
            //绑定基本信息
            var user = CookieData.getInstance().YHXX;
            txt_QQ.InputText = user.QQ;
            txt_YY.InputText = user.YY;
            txt_ZBFJH.InputText = user.ZBFJH;
            cob_DDLX.SelectedValue = user.DDLX;
            cob_ZBFS.SelectedValue = user.ZBFS;
        }

        private void init()
        {
            //读档类型
            List<Cookie_ZD> ls_ddlx = CookieData.getInstance().ZDGL.Where(a => a.ZDDM == "CDDLX").ToList();
            List<KeyValuePair<string, string>> lscbm_ddlx = new List<KeyValuePair<string, string>>();

            foreach (var item in ls_ddlx)
            {
                lscbm_ddlx.Add(new KeyValuePair<string, string>(item.MXZ, item.MXMC));
            }
            cob_DDLX.Source = lscbm_ddlx;
            cob_DDLX.SelectedValue = "全套";

            //直播方式
            List<Cookie_ZD> ls_zbfs = CookieData.getInstance().ZDGL.Where(a => a.ZDDM == "ZBFS").ToList();
            List<KeyValuePair<string, string>> lscbm_zbfs = new List<KeyValuePair<string, string>>();

            foreach (var item in ls_zbfs)
            {
                lscbm_zbfs.Add(new KeyValuePair<string, string>(item.MXMC, item.MXZ));
            }
            cob_ZBFS.Source = lscbm_zbfs;
            cob_ZBFS.SelectedValue = "虎牙";
        }
    }
}
